home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-12-12 | 4.9 KB | 172 lines | [TEXT/PJMM] |
- { In-memory item list for dialog with four items:}
-
- { 1 "^0^1^2^3" (static text)}
- { 2 Button 1}
- { 3 Button 2}
- { 4 Button 3}
-
- { The caller of FakeAlert passes the four strings that are to be}
- { substituted into the first item, the number of buttons that}
- { should be used, and the titles to put into each button.}
- { A copy of the item list is hacked to use the right number of}
- { buttons.}
-
- { Thanks to Erik Kilk and Jason Haines. Some of the stuff to do}
- { this is modified from code they wrote.}
-
- { Ported to LightSpeed Pascal 8 January 1987 Owen Hartnett }
-
- unit FakeAlert;
-
- interface
- {$IFC UNDEFINED THINK_PASCAL}
- uses
- Memtypes, Quickdraw, OSIntf, ToolIntf, PackIntf;
- {$ENDC}
-
- function FakeAlert (s1, s2, s3, s4: Str255; nButtons, defButton: integer; t1, t2, t3: Str255): integer;
- implementation
-
- var
- ItemList: array[0..32] of integer;
-
- savePort: GrafPtr;
- theDialog: DialogPtr;
- iListHandle: Handle;
- bounds: Rect;
- itemHit: integer;
-
- procedure InitItemList;
-
- {This proc performs static initializations on ItemList }
-
- begin
- Itemlist[0] := 3; { max number of items - 1 }
- Itemlist[1] := 0; { statText item}
- { reserve a long for item handle }
- itemlist[2] := 0; { display rectangle }
- Itemlist[3] := 10;
- Itemlist[4] := 27;
- itemlist[5] := 61;
- Itemlist[6] := 225;
- Itemlist[7] := $8808; { 8 + 128 = statText (disabled), title 8 bytes long }
- itemlist[8] := $5e30; { ^0^1^2^3 }
- Itemlist[9] := $5e31;
- Itemlist[10] := $5e32;
- itemlist[11] := $5e33;
- { first button}
- Itemlist[12] := 0; { reserve a long for item handle }
- Itemlist[13] := 0;
- itemlist[14] := 104; { display rectangle }
- Itemlist[15] := 140;
- Itemlist[16] := 124;
- itemlist[17] := 210;
- Itemlist[18] := $400; { 4 = pushButton, title is 0 bytes long}
- { second button}
- Itemlist[19] := 0; { reserve a long for item handle }
- itemlist[20] := 0;
- Itemlist[21] := 104; { display rectangle }
- Itemlist[22] := 30;
- itemlist[23] := 124;
- Itemlist[24] := 100;
- Itemlist[25] := $400; { 4 = pushButton, title is 0 bytes long}
- { third button}
- itemlist[26] := 0; { reserve a long for item handle }
- Itemlist[27] := 0;
- Itemlist[28] := 72; { display rectangle }
- itemlist[29] := 30;
- Itemlist[30] := 92;
- Itemlist[31] := 100;
- itemlist[32] := $400; { 4 = pushButton, title is 0 bytes long}
- end;
-
- { Set dialog button title and draw bold outline if makeBold true.}
- { This must be done after the window is shown or else the bold}
- { outline won't show up (which is probably the wrong way to do it).}
-
- procedure SetDControl (theDialog: DialogPtr; itemNo: integer; title: Str255; makeBold: Boolean);
- var
- itemHandle: Handle;
- itemType: integer;
- itemRect: Rect;
- pState: PenState;
-
- begin
- GetDItem(theDialog, itemNo, itemType, itemHandle, itemRect);
- SetCTitle(ControlHandle(itemHandle), title);
- if makeBold then
- begin
- GetPenState(pState);
- PenNormal;
- PenSize(3, 3);
- InsetRect(itemRect, -4, -4);
- FrameRoundRect(itemRect, 16, 16);
- SetPenState(pState);
- end;
- end;
-
- { Fake an alert, using an in-memory window and item list.}
- { The message to be presented is constructed from the first}
- { four arguments. nButtons is the number of buttons to use,}
- { defButton is the default button, the next three args are}
- { the titles to put into the buttons. The return value is}
- { the button number (1..nButtons). This must be interpreted}
- { by the caller, since the buttons may be given arbitrary}
- { titles.}
-
- { nButtons should be between 1 and 3, inclusive.}
- { defButton should be between 1 and nButtons, inclusive.}
-
- function FakeAlert;
- var
- savePort: GrafPtr;
- theDialog: DialogPtr;
- iListHandle: Handle;
- bounds: Rect;
- itemHit: integer;
-
- begin
- InitItemList;
- InitCursor;
- GetPort(savePort);
- iListHandle := NewHandle(longint(512));
- HLock(iListHandle);
- ItemList[0] := nButtons; { = number items - 1 }
- BlockMove(@ItemList[0], iListHandle^, longint(512));
- SetRect(bounds, 115, 80, 355, 220);
- theDialog := NewDialog(nil, bounds, '', false, dBoxProc, WindowPtr(-1), false, longint(0), iListHandle);
- ParamText(s1, s2, s3, s4); { construct message }
- SetPort(theDialog);
- ShowWindow(theDialog);
-
- case nButtons of { set button titles }
- 3:
- begin
- SetDControl(theDialog, 4, t3, defButton = 3);
- SetDControl(theDialog, 3, t2, defButton = 2);
- SetDControl(theDialog, 2, t1, defButton = 1);
- end;
- 2:
- begin
- SetDControl(theDialog, 3, t2, defButton = 2);
- SetDControl(theDialog, 2, t1, defButton = 1);
- end;
- 1:
- SetDControl(theDialog, 2, t1, defButton = 1);
- end;
-
- { ModalDialog returns 1 if return/enter hit, which, since}
- { the statText item is first, can be unambiguously}
- { interpreted as "choose default".}
-
- ModalDialog(nil, itemHit);
- if itemHit = 1 then
- itemHit := defButton
- else
- itemHit := itemHit - 1;
- HUnlock(iListHandle);
- DisposDialog(theDialog);
- SetPort(savePort);
- FakeAlert := itemHit;
- end;
- end.